package com.edooteach.api.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.edoomath.entity.tecent.WechatAccount;
import com.edoomath.entity.tecent.WechatOpenid;
import com.edoomath.entity.user.User;
import com.edoomath.entity.user.UserCredit;
import com.edoomath.entity.user.UserSource;
import com.edoomath.entity.user.UserWallet;

/**
 * 
 * @author mohanlan
 *
 */
@Dao(value = "hibernate")
public interface UserDao {
    
    /**
     * load user by unionid
     * 
     * @param unionid
     * @return
     */
    @Query("FROM User WHERE unionid = :unionid AND disabled = false")
    public User loadUser(@Variable("unionid") String unionid);
    
    /**
     * 
     * 
     * @param mobile
     * @return
     */
    @Query("FROM User WHERE mobile = :mobile AND disabled = false AND children = false")
    public User getParent(@Variable("mobile") String mobile);
    
    /**
     * 
     * @param mobile
     * @return
     */
    @Query("FROM User WHERE mobile = :mobile AND disabled = false")
    public User loadUserByMobile(@Variable("mobile") String mobile);
    
    /**
     * load wechatAccount by unionid
     * 
     * @param unionid
     * @return
     */
    @Query("FROM WechatAccount WHERE unionid = :unionid")
    public WechatAccount loadAccount(@Variable("unionid") String unionid);
    
    /**
     * 
     * @param unionid
     * @param source
     * @return
     */
    @Query("FROM WechatOpenid WHERE unionid = :unionid AND source = :source")
    public WechatOpenid loadOpenid(@Variable("unionid") String unionid, @Variable("source") UserSource source);
    
    /**
     * 
     * @param user
     * @return
     */
    @Query("FROM UserWallet WHERE user = :user AND disabled = false")
    public UserWallet loadWallet(@Variable("user") User user);
    
    /**
     * 
     * @param user
     * @return
     */
    @Query("FROM UserCredit WHERE user = :user AND disabled = false")
    public UserCredit loadCredit(@Variable("user") User user);
}
